<?php 
require_once "../../config.php";
require_once "../../functions.php";
//获取从前端得到的是当前是第几页，每页获取多少条，连接数据库获取数据
$currentPage = $_POST['currentPage'];
$pageSize = $_POST['pageSize'];

$connect = connect();
$offset = ($currentPage - 1) * $pageSize;
$sql = "select c.id,c.author,c.content,c.created,c.status,p.title from comments c left join posts p on p.id = c.post_id limit {$offset},{$pageSize};";
$queryResult = query($connect,$sql);
$sql1 = "select count(*) as total from comments";
$countArr = query($connect,$sql1);
$count = $countArr[0]['total'];
$pageCount = ceil($count / $pageSize); 
header('content-type:application/json;charset=utf8');
$response = ["code"=>0,"msg"=>"操作失败"];
if($queryResult){
    $response["code"] = 1;
    $response["msg"] = "操作成功";
    $response["data"] = $queryResult;
    $response["pageCount"] = $pageCount;
}
echo json_encode($response);
?>